package lxq.away3d;

import away3d.containers.ObjectContainer3D;
import away3d.containers.View3D;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;



class EasyAway3D extends Sprite{
	private var _view:View3D;
	private var _debugMode:Bool;
	public function new(debugMode:Bool = true, anti:UInt = 8, bgColor:UInt = 0x376C55, frameRate:UInt = 60) {
		super();
		addEventListener(Event.ADDED_TO_STAGE, added);
	}

	private function added(e:Event):Void {
		removeEventListener(Event.ADDED_TO_STAGE, added);
		stage.scaleMode = StageScaleMode.NO_SCALE;
		stage.align = StageAlign.TOP_LEFT;
		_view = new View3D();
		addChild(_view);
		_view.camera.x=_view.camera.y =0;
		_view.camera.z=-800;
		initScene();
		addEventListener(Event.ENTER_FRAME, _onEnterFrame);
		stage.addEventListener(Event.RESIZE, onResize);
		onResize();
	}
	private function initScene():Void{
		trace("oh yeah~away3d.");
	}
	public function addObject3D(child:ObjectContainer3D):Void{
		_view.scene.addChild(child);
	}
	private function _onEnterFrame(e:Event):Void{
		_view.render();
		utils();
	}
	private function utils():Void{};
	private function onResize(event:Event = null):Void{
		_view.width = stage.stageWidth;
		_view.height = stage.stageHeight;
	}
}